import pygame
from lab import *

def newDang():
    pygame.init()
    resolution = (800, 640)
    screen = pygame.display.set_mode(resolution)
    pygame.display.set_caption("Random Dungeon Generator")

    clock = pygame.time.Clock()
    fps = 25

    background = pygame.surface.Surface(resolution)
    background.fill((100, 200, 50))
  
    dg = dang()
    dg.generate(50, 40)

    fn = pygame.font.SysFont('Arial', 36)
    running = True
    while running:
        clock.tick(fps)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    running = False
                elif event.key == pygame.K_SPACE:
                    del dg.coridors[:]
                    del dg.rooms[:]
                    dg.generate(50, 40)


        keypressed = pygame.key.get_pressed()
        if keypressed[pygame.K_w] or keypressed[pygame.K_UP]:
            pass

        if keypressed[pygame.K_s] or keypressed[pygame.K_DOWN]:
            pass
        #if keypressed[pygame.K_a] or keypressed[pygame.K_LEFT]:
         
        #if keypressed[pygame.K_d] or keypressed[pygame.K_RIGHT]:

        screen.blit(background, (0, 0))
        for r in dg.rooms:
            fl = pygame.surface.Surface((r.w*8,r.h*8))
            fl.fill((0,0,255))
            screen.blit(fl, (r.x*8, r.y*8))
        
        for c in dg.coridors:    
            pygame.draw.lines(screen,(0,0,255),False,[(x*8,y*8) for (x,y) in c],8)
        screen.blit(fn.render(str(len(dg.coridors)),True,(0,0,255)),(10,10))
        pygame.display.flip()    

def tryto():
    pygame.init()
    resolution = (800, 640)
    screen = pygame.display.set_mode(resolution)
    pygame.display.set_caption("Random Dungeon Generator")

    clock = pygame.time.Clock()
    fps = 25

    background = pygame.surface.Surface(resolution)
    background.fill((100, 200, 50))

    sc = lab(800,640,15,20,200)
    sc.generate();
    
    dg = dang()
    dg.generate(50, 40)

    bc = lab(800,640,30,15,50)
    bc.generate();

    fn = pygame.font.SysFont('Arial', 36)
    running = True
    while running:

        clock.tick(fps)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    sc.clear()
                    sc.generate();
                    bc.clear()
                    bc.generate();
                    
                elif event.key == pygame.K_SPACE:
                    running = False


        keypressed = pygame.key.get_pressed()
        if keypressed[pygame.K_w] or keypressed[pygame.K_UP]:
            sc.clear()
            sc.generate(sc.roomcount+1);
            bc.clear()
            bc.generate(sc.roomcount+1);

        if keypressed[pygame.K_s] or keypressed[pygame.K_DOWN]:
            sc.clear()
            sc.generate(sc.roomcount-1);
            bc.clear()
            bc.generate(sc.roomcount+1);
         
        #if keypressed[pygame.K_a] or keypressed[pygame.K_LEFT]:
         
        #if keypressed[pygame.K_d] or keypressed[pygame.K_RIGHT]:

        screen.blit(background, (0, 0))
        for r in sc.rooms:
            fl = pygame.surface.Surface((r.w,r.h))
            fl.fill((0,0,0))
            screen.blit(fl, (r.x, r.y))
            #pygame.draw.rect(screen,(255,0,0),pygame.Rect((r.x, r.y),(r.w,r.h)),2)
        for r in bc.rooms:
            fl = pygame.surface.Surface((r.w,r.h))
            fl.fill((0,0,255))
            screen.blit(fl, (r.x, r.y))

        screen.blit(fn.render(str(sc.roomcount),True,(0,0,255)),(10,10))
        pygame.display.flip()







if __name__ == "__main__":
    newDang()
